package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class HttpServletContext extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public HttpServletContext() {
    	
    }

    public void inti(ServletConfig servletConfig) {
    	ServletContext servletContext = servletConfig.getServletContext();
    	System.out.println(servletContext);
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		ServletContext servletContext = super.getServletContext();

		String path = servletContext.getRealPath("/");
		@SuppressWarnings("unchecked")
		Set<String> set = servletContext.getResourcePaths("/");
		// <!--解决中文乱码-->
		response.setCharacterEncoding("UTF-8");// 只对post请求有效
		response.setHeader("content-type","text/html;charset=UTF-8");
		
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
		out.println("<body>");
		out.println("path为:" + path + " set :" + set);
		out.println("</body>");
		out.println("</html>");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
